package com.neusoft.meal.service.impl;

import com.neusoft.meal.dao.MealPlanDao;
import com.neusoft.meal.po.MealPlan;
import com.neusoft.meal.po.ResponseBean;
import com.neusoft.meal.service.MealPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MealPlanServiceImpl implements MealPlanService {

    @Autowired
    private MealPlanDao mealPlanDao;

    @Override
//    查询启用状态的膳食安排
    public ResponseBean<List<MealPlan>> getAllMealPlans() {
//        List<MealPlan> mealPlans = mealPlanDao.selectList(new QueryWrapper<MealPlan>().eq("status", "启用"));
        List<MealPlan> mealPlans = mealPlanDao.selectList(null);
        return new ResponseBean<>(mealPlans);
    }

    @Override
    public ResponseBean<MealPlan> getMealPlanById(Integer planId) {
        MealPlan mealPlan = mealPlanDao.selectById(planId);
        if (mealPlan != null) {
            return new ResponseBean<>(mealPlan);
        } else {
            return new ResponseBean<>(404, "膳食计划未找到");
        }
    }

    @Override
    public ResponseBean<Integer> addMealPlan(MealPlan mealPlan) {
        int result = mealPlanDao.insert(mealPlan);
        return new ResponseBean<>(result); // 返回插入成功的行数
    }

    @Override
    public ResponseBean<Integer> updateMealPlan(MealPlan mealPlan) {
        int result = mealPlanDao.updateById(mealPlan);
        return new ResponseBean<>(result); // 返回更新成功的行数
    }

    @Override
    public ResponseBean<Integer> deleteMealPlan(Integer planId) {
        int result = mealPlanDao.deleteById(planId);
        return new ResponseBean<>(result); // 返回删除成功的行数
    }
}